import { ref } from 'vue'
import { defineStore } from 'pinia'
import { loginApi, refreshApi } from '@/apis/system/login.js'

export const useTokenStore = defineStore('Admin_Token',()=>{
      
    // token信息
    const token = ref('');

    // 保存token信息
    const saveToken = async(data) => {
        const res = await loginApi(data);
        token.value = res.data;
    };

    // 清理token信息
    const clearToken = () => {
        token.value = '';
    };

    // 刷新token
    const refreshToken=async()=>{
        const res = await refreshApi();
        token.value = res.data;
    }

    // return
    return { 
        token,
        saveToken,
        clearToken,
        refreshToken,
    }
},
{
    persist: true
})

export default useTokenStore